package com.mnc.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
@Entity
public class UserUnit implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4876030409883139090L;

	//主键id
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int unitId;
	//团名称
	@Column
	private String unitName;
	//团简介
	@Column
	private String unitDesc;
	//建团时间
	@Column
	private Date createDate;
	//创建者
	@ManyToOne(cascade={CascadeType.REFRESH})
	private User creater;
	//团成员
	@ManyToMany(cascade={CascadeType.REFRESH},fetch=FetchType.EAGER)
	@JoinTable(name="Users_Units",
	joinColumns= {@JoinColumn(name="userId")},
	inverseJoinColumns= {@JoinColumn(name="unitId")})
	private Set<User> members=new HashSet<User>();
	//语录
	@OneToMany(mappedBy="onUnit",cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
	@MapKey(name="talkDate")
	private Set<UnitTalk> unitTalks= new HashSet<UnitTalk>();
	
	public int getUnitId() {
		return unitId;
	}
	public void setUnitId(int unitId) {
		this.unitId = unitId;
	}
	public String getUnitName() {
		return unitName;
	}
	public void setUnitName(String unitName) {
		this.unitName = unitName;
	}
	public String getUnitDesc() {
		return unitDesc;
	}
	public void setUnitDesc(String unitDesc) {
		this.unitDesc = unitDesc;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public User getCreater() {
		return creater;
	}
	public void setCreater(User creater) {
		this.creater = creater;
	}
	public Set<User> getMembers() {
		return members;
	}
	public void setMembers(Set<User> members) {
		this.members = members;
	}
	public Set<UnitTalk> getUnitTalks() {
		return unitTalks;
	}
	public void setUnitTalks(Set<UnitTalk> unitTalks) {
		this.unitTalks = unitTalks;
	}
	
}
